package ch.mustaffah.aoide.model;

public class ScoreContainer {
	private Score[] scoreArray;
	private int octave = 3;

	public int getOctave() {
		return octave;
	}

	public void setOctave(int octave) {
		this.octave = octave;
	}

	public ScoreContainer() {
		this.scoreArray = new Score[12];
		// initialize empty
		ScorePattern emptyPattern = new ScorePattern(null);
		this.scoreArray = emptyPattern.getPattern();
		this.octave = 0;
	}

	public void applyScorePattern(ScorePattern pattern) {
		this.scoreArray = pattern.getPattern();
	}

	@Override
	public String toString() {
		String result = "";
		for (int i = 0; i < this.scoreArray.length; i++) {
			result = result + this.scoreArray[i].toString();
		}
		return result;
	}

	public Score[] getScorePattern() {
		return this.scoreArray;
	}

	public void transpose(int ht) {
		//transpose only within 12 notes
		if (scoreArray != null && ht<11) {
			Score[] newScoreArray = new Score[12];
			for (int i = 0; i < scoreArray.length; i++) {
				int newPosition=i+ht;
				//shift down when reaching octave
				if(newPosition>11){
					newPosition=newPosition-12;
				}
				newScoreArray[newPosition]=scoreArray[i];
			}
			//set the new array
			scoreArray=newScoreArray;
		}
	}

}
